package com.sven.helloservice;

import com.sven.helloapi.HelloServiceAPI;
import com.sven.helloapi.User;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.atomic.AtomicInteger;


@RestController
public class HelloController implements HelloServiceAPI {
    private static Logger logger = LoggerFactory.getLogger(HelloController.class);

    @Value("${server.port}")
    String port;

    private AtomicInteger count = new AtomicInteger();

    @RequestMapping(value = "/hello/hello1", method = RequestMethod.GET)
    public String hello1(){
        logger.info("进入hello1");
        System.out.println("进入hello1");

        // 模拟异常，调用端fallbanck
        // int i=1/0;
        // try {
        //     System.out.println("准备睡");
        //     Thread.sleep(500);
        // } catch (InterruptedException e) {
        //     e.printStackTrace();
        // }
        //
        // int i = count.getAndIncrement();
        // System.out.println(port+"====第：" + i + "次调用");
        return "privoder：端口是"+port;
    }

    @RequestMapping(value = "/api/v1/hello/hello11", method = RequestMethod.GET)
    public String hello11(){
        return "/api/v1===privoder：端口是"+port;
    }

    @Override
    public String hello6(String name) {
        return "你好："+name;
    }

    @Override
    public User hello7(String name, Integer age) {
        return new User(name, age);
    }

    @Override
    public String hello8(User user) {
        System.out.println(ToStringBuilder.reflectionToString(user));
        return user.toString();
    }
}
